<template>
  <div class="toBtoC-tab1">
    <p class="g-unit">单位: 万元</p>
    <div class="tableBox">
      <el-table
        v-loading="tableLoading"
        :data="tableData"
        height="85vh"
        style="width: 100%"
        class="tableTh28"
        border
        stripe
        ref="table"
      >
        <el-table-column label="单位" prop="areaName" class-name="first-title" min-width="40"></el-table-column>
        <el-table-column :label="item.name" :key="index" v-for="(item, index) in titleList">
          <el-table-column
            :label="it.label"
            :prop="it.prop"
            :key="it.label"
            v-for="it in item.props"
          ></el-table-column>
        </el-table-column>
        <!-- <el-table-column
          class-name="right-money"
          v-for="(item,index) in titleList"
          min-width="84"
          :key="index"
          :label="item.areaName"
          :prop="item.indexKey"
        ></el-table-column>-->
      </el-table>
    </div>
  </div>
</template>

<script>
import { $budgetAPI } from "@/api";
export default {
  name: "incomeDay-tab1",
  props: ["paramsObj"],
  data() {
    return {
      tableData: [],
      tableLoading: false,
      titleList: [],
    };
  },
  mounted() {
    this.init(this.paramsObj)
  },
  methods: {
    init(obj) {
      let that = this;
    
      that.tableLoading = true;
      $budgetAPI.incomeDaily22022(
        { areaId: obj.areaId, acctDay: obj.time.replace(/-/g, ''), isActual: obj.isActual },
        (res) => {
          if (res.code == 0) {
            res.content.data.map((item) => {
              item.dataList.map((it, i) => {
                item[i + "indexValue"] = it.indexValue;
                item[i + "upIndexValue"] = it.upIndexValue;
                item[i + "changeIndexValue"] = it.changeIndexValue;
                item[i + "incrementRate"] = it.incrementRate;
              });
            });
            that.tableData = res.content.data;
            // res.content.titles.map((item) => {});
            for (let i = 0; i < res.content.titles.length; i++) {
              that.titleList[i] = {
                name: res.content.titles[i],
                props: [
                  {
                    prop: i + "indexValue",
                    label: "本月累计数",
                    
                  },
                  {
                    prop: i + "upIndexValue",
                    label: "上月同期数",
                  },
                  {
                    prop: i + "changeIndexValue",
                    label: "变化",
                  },
                  {
                    prop: i + "incrementRate",
                    label: "增长率",
                  },
                ]
              };
              // for (let j = 0; j < 4; j++) {
              //   debugger
              //   that.titleList[i].props[j].[i + "indexValue"] = i + "indexValue";
              //   that.titleList[i].props[j].[i + "upIndexValue"] = i + "upIndexValue";
              //   that.titleList[i].props[j].[i + "changeIndexValue"] = i + "changeIndexValue";
              //   that.titleList[i].props[j].[i + "incrementRate"] =  i + "incrementRate";
              //   }
              // }
              
            }

            that.tableLoading = false;
            // this.colDefList = res.content.colDefList;
            // this.fileName = res.content.fileName;
            // setTimeout(() => {
            //   this.$refs.tab2.init();
            //   this.$refs.tab2.tableLoading = false;
            // }, 500);
          } else {
            this.alertError(res);
          }
        },
        (err) => {
          console.log(err);
        }
      );
    },
  },
};
</script>

<style lang="scss" scoped>
</style>